﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ThreeByte.ActiveDeck.Data;
using ThreeByte.ActiveDeck.Service;

namespace ThreeByte.ActiveDeck.Web.GetStarted
{
    public partial class Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e) {
            GoButton.Attributes.Add("onmouseover", "this.src='sendDownload_over.png'");
            GoButton.Attributes.Add("onmouseout", "this.src='sendDownload.png'");
        }

        protected void GoButton_Click(object sender, ImageClickEventArgs e) {
            //Submit the email address asynchronously

            string email = EmailTextBox.Text;
            //Validate the text box

            try {
                Guid key = DataUtil.RecordDownloadRequest(email);
                EmailUtil.SendInvitationEmail(email, key);
                EmailLabel.Visible = false;
                EmailTextBox.Visible = false;
                SuccessText.Text = "Great!  Go check your email for a link to download the software.";
            } catch(Exception ex) {
                SuccessText.Text = "Sorry, that email address doesn't seem valid.  Please check and try again.";
            }
            //Update the screen
            SuccessText.Visible = true;
            
        }
    }
}